<template>
  <div
    class="xtx-skeleton"
    :class="{ active: animated }"
    :style="{ width, height, backgroundColor: bg }"
  ></div>
</template>

<script>
export default {
  name: 'XtxSkeleton',
  props: {
    width: {
      type: String,
      default: '100px'
    },
    height: {
      type: String,
      default: '100px'
    },
    bg: {
      type: String,
      default: '#efefef'
    },
    animated: {
      type: Boolean,
      default: true
    }
  }
}
</script>

<style scoped lang="less">
.xtx-skeleton {
  overflow: hidden;
  position: relative;
  display: inline-block;
  vertical-align: middle;
}
.active {
  &:after {
    content: '';
    position: absolute;
    width: 40%;
    height: 100%;
    left: 0;
    top: 0;
    background: linear-gradient(
      to left,
      rgba(255, 255, 255, 0) 0,
      rgba(255, 255, 255, 0.3) 50%,
      rgba(255, 255, 255, 0) 100%
    );
    transform: skewX(45deg);
    animation: move 1s ease 0.2s infinite;
  }
}
@keyframes move {
  from {
    left: -100%;
  }
  to {
    left: 120%;
  }
}
</style>
